<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('处理信件工单初稿')"/>
    <link th:href="@{/ajax/libs/bootstrap-switch/bootstrap-switch.min.css}" rel="stylesheet">
    <link th:href="@{/ajax/libs/bootstrap-tagsinput/tagsinput.css}" rel="stylesheet">
    <link th:href="@{/ajax/libs/jQuery-ui/jquery-ui.css}" rel="stylesheet">
    <link th:href="@{/css/iconfont/iconfont.css}" rel="stylesheet">
    <link rel="stylesheet" type="text/css" th:href="@{/ajax/libs/qxEasyUI/themes/default/easyui.css}">


</head>
<style>
    label {
        font-weight: bold;
    }
    @font-face {
        font-family: 'huawen';
        src: url("/fonts/huawen.woff2");
    }
</style>

<body style="background-color: #F4F6FA; font-size: 13px;font-family:'huawen' ;font-weight: bold">
<div class="main-content" style="margin: 0;padding: 0;letter-spacing:2px;">

    <form id="form-user-add" th:object="${workFormBase}" class="form-horizontal" style="background-color: #F4F6FA">
        <input type="hidden" value="1" id="zjflag">
        <input id="pkId" name="pkId" type="hidden" th:field="*{pkId}"/>
        <input id="flagInt" name="flagInt" type="hidden" th:field="*{flagInt}"/>
        <input id="iptTime" name="iptTime" type="hidden" th:field="*{iptTime}"/>
        <input id="flagString" name="flagString" type="hidden" th:field="*{flagString}">
        <input id="spareInt" name="spareInt" type="hidden" th:field="*{spareInt}"/>
        <input id="originFK" name="originFK" type="hidden" th:field="*{originFK}"/>
        <input id="txtWsFlag" name="wsUFlag" type="hidden" th:field="*{wsUFlag}"/>
        <input id="fmCerNO" name="fmCerNO" type="hidden" th:field="*{fmCerNO}"/>
        <input id="fmCerName" name="fmCerName" type="hidden" th:field="*{fmCerName}">
        <input id="spareString" name="spareString" type="hidden" th:field="*{spareString}">
        <input name="crtStepId" type="hidden" value="400">
        <input name="crtStepName" type="hidden" value="市级部门处理">
        <!-- 附件字段 -->
        <input id="fmSpareB" name="fmSpareB" type="hidden" th:field="*{fmSpareB}"/>
        <input id="FKInt" name="FKInt" type="hidden" th:field="*{FKInt}"/>
        <input type="hidden" id="mark" name="mark" th:field="*{mark}">
        <!-- 查看附件 -->
        <input type="hidden" id="ySpare" name="ySpare" th:value="${ySpare}" />
        <!-- 附件字段 -->
        <div class="grid-container" style="display: flex">
            <!--     左       -->
            <div class="col-sm-8 entering-page">
                <!--内上-->
                <div class="col-sm-12" style="margin-top: 10px">
                    <!--来信类容-->
                    <div id="fmContent"
                         style="padding: 5px;background-color: #FAFAFA;border-radius: 12px; height: 80px">
                        [[*{fmContent}]]
                    </div>
                </div>
                <!--内左-->
                <div class="col-sm-6">
                    <!--   来信基本信息     -->
                    <div class="col-sm-12 tltieBoder">
                        <div class="blueBorder"></div>
                        <h4 style="margin:0 0 0 10px">来信基本信息</h4>
                    </div>
                    <!--事发地址-->
                    <div class="form-group col-sm-12">

                        <label class="col-sm-3 control-label  entering-pd">事发地址：</label>
                        <div class="col-sm-9">
                            <span class="tworkformprocess-span">[[*{fmAddress}]]</span>
                            <input name="fmAddress" th:field="*{fmAddress}" type="hidden"/>
                        </div>


                    </div>

                    <div class="form-group col-sm-12">
                        <label class="col-sm-3  control-label entering-pd">流水号：</label>
                        <div class="col-sm-9">
                            <span class="tworkformprocess-span">[[*{wsCode}]]</span>
                            <input name="wsCode" th:field="*{wsCode}" type="hidden"/>
                        </div>
                    </div>
                    <div class="form-group col-sm-12">
                        <label class="col-sm-3 control-label entering-pd">提取码：</label>
                        <div class="col-sm-9">
                            <span class="tworkformprocess-span">[[*{wsKey}]]</span>
                            <input name="wsKey" th:field="*{wsKey}" type="hidden"/>
                        </div>
                    </div>
                    <div class="form-group col-sm-12">
                        <label class="col-sm-3 control-label entering-pd">电子邮件：</label>
                        <div class="col-sm-9">
                            <span class="tworkformprocess-span">[[*{fmEmail}]]</span>
                            <input name="fmEmail" th:field="*{fmEmail}" type="hidden"/>
                        </div>
                    </div>
                    <div class="form-group col-sm-12">
                        <label class="col-sm-3 control-label entering-pd">地区：</label>
                        <div class="col-sm-9">
                            <select name="fmAreaNo" th:field="*{fmAreaNo}" id="fmAreaNo"
                                    onchange="dropChgSendTextOnly(this,'fmAreaName');"
                                    th:with="district=${@commonServiceImpl.findArea()}" class="form-control formSelect"
                                    required>
                                <option value="">--请选择--</option>
                                <option th:each="item : ${district}" th:text="${item['CSText']}"
                                        th:value="${item['CSValue']}"></option>
                            </select>
                            <input type="hidden" id="fmAreaName" name="fmAreaName" th:value="*{fmAreaName}"/>
                        </div>
                    </div>

                    <!-- 单选-->
                    <div class="form-group col-sm-12">
                        <label class="col-sm-3 control-label entering-pd" style="padding-top: 1px">自动延期：</label>
                        <div class="col-sm-9">
                            <input name="isAutoExtend" th:checked="${isAutoExtend} == 1" th:value="${isAutoExtend}"
                                   type="checkbox" data-size="small">
                        </div>
                    </div>
                    <div class="form-group col-sm-12">
                        <label class="col-sm-3 control-label entering-pd" style="padding-top: 1px">同意公开：</label>
                        <div class="col-sm-3">
                            <input name="openFrom" th:checked="*{openFrom == 1}" th:value="*{openFrom}"
                                   type="checkbox" data-size="small">
                        </div>
                        <label class="col-sm-3 control-label entering-pd" style="padding-top: 1px">建议公开：</label>
                        <div class="col-sm-3">
                            <input name="openX" th:checked="*{openX == 1}" th:value="*{openX}"
                                   type="checkbox" data-size="small">
                        </div>
                    </div>

                    <div class="form-group col-sm-12">
                        <label class="col-sm-3 control-label entering-pd" style="padding-top: 1px">性别：</label>
                        <div class="col-sm-3">
                            <input name="fromSex" th:checked="*{fromSex == 1}" th:value="*{fromSex}"
                                   type="checkbox" data-size="small">
                        </div>
                        <label class="col-sm-3 control-label entering-pd" style="padding-top: 1px">摘报：</label>
                        <div class="col-sm-3">
                            <input name="reportFlag" th:checked="*{reportFlag == 1}" th:value="*{reportFlag}"
                                   type="checkbox" data-size="small">
                        </div>
                    </div>
                </div>
                <!--内右-->
                <div class="col-sm-6" style="border-left: 1px solid #ebebeb">

                    <!--   工单基本信息     -->
                    <div class="col-sm-12 " style="display: flex;justify-content: space-between">
                        <div class="tltieBoder">
                            <div class="blueBorder"></div>
                            <h4 style="margin:0 0 0 10px">工单基本信息</h4>
                        </div>
                        <!--呈批-->
                        <div class="col-sm-6 control-label">
                            <input type="hidden" id="fmSpare" name="fmSpare" th:value="${mmailGetDeal.fmSpare}" />
                            <button type="button" class="btn btn-sm btn-primary"
                                    style="margin-top: 9px;color: #206ef7;background-color: white" th:if="${#strings.isEmpty(mmailGetDeal.flagString)}"
                                    onclick="transfer()" id="ZJ">呈批
                            </button>
                            <button type="button" class="btn btn-sm btn-primary"
                                    style="margin:3px 50px 0px 15px;" th:unless="${#strings.isEmpty(mmailGetDeal.flagString)}"
                                    title="呈批领导信箱" id="ZJOK">已呈批</button>
                        </div>
                    </div>

                    <div class="form-group col-sm-12">
                        <label class="col-sm-3 control-label  entering-pd">来信类型：</label>
                        <div class="col-sm-9">
                            <select name="dfmClaNo" id="dfmClaNo" required
                                    th:with="telTypes=${@commonServiceImpl.findTelType()}"
                                    onchange="dropChgSendTextOnly(this,'dfmClaName');"
                                    class="form-control formSelect">
                                <option value="">--请选择--</option>
                                <th:block th:each="item : ${telTypes}">
                                    <option th:text="${item['CSText']}" th:value="${item['CSValue']}"
                                            th:selected="${item['CSValue'] eq workFormBase.dfmClaNo}"></option>
                                </th:block>
                            </select>
                            <input type="hidden" name="dfmClaName" id="dfmClaName" th:value="*{dfmClaName}"/>
                        </div>
                    </div>
                    <!--内容类别-->
                    <div class="form-group col-sm-12">
                        <label class="col-sm-3 control-label entering-pd">内容类别：</label>
                        <div class="col-sm-9">
                            <input id="qxCT" th:value="*{dcntAName}" style="width:242px;height:31px;">
                            <input id="txtDcntAcode" name="dcntACode" type="hidden" th:value="*{dcntACode}"/>
                            <input id="txtDCntAName" name="dcntAName" type="hidden" th:value="*{dcntAName}"/>
                        </div>
                    </div>
                    <!--工单主题-->
                    <div class="form-group col-sm-12">
                        <label class="col-sm-3 control-label entering-pd">工单主题：</label>
                        <div class="col-sm-9">
                            <input id="fromTopic" name="fromTopic" th:field="*{fromTopic}" placeholder="请输入"
                                   class="form-control workTheme" type="text"
                                   required="">
                        </div>
                    </div>
                    <!--拟办期限-->
                    <div class="form-group col-sm-12">
                        <label class="col-sm-3 control-label  entering-pd">来信时间：</label>
                        <div class="col-sm-9">
                            <input name="fromTime" th:field="*{fromTime}" placeholder="请输入" class="form-control deadline"
                                   type="text"
                                   required="">
                            <div class="input-group-append my-time-icon">
                                <span class="glyphicon glyphicon-calendar "></span>
                            </div>
                        </div>
                    </div>

                    <!-- 工单备注-->
                    <div class="form-group col-sm-12">
                        <label class="col-xs-3 control-label entering-pd">工单备注：</label>
                        <div class="col-xs-9">
                                    <textarea name="wfRemark" th:field="*{wfRemark}" maxlength="3500"
                                              class="form-control workRemark"
                                              rows="3" style="height: 65px"></textarea>
                            <span class="tworkformprocess-span">还可以输入<i class="workRemarkI">3500</i>个文字</span>
                        </div>
                    </div>
                </div>
                <!--内下-->
                <div class="col-sm-12" style="margin-top: -16px">
                    <div class="col-sm-12">
                        <div class="btn-group-sm" id="toolbar" role="group">
                            <label class="control-label"> <a class="btn btn-success btn-sm" onclick="proposed()">
                                <i class="fa fa-plus"></i> 新增
                            </a></label>
                            <label class="control-label">
                                <a class="btn btn-success btn-sm" th:if="${ySpare != null && #strings.length(ySpare) > 10}" onclick="lookImage(this)">查看附件</a>
                            </label>
                            <!--                            <a th:if="${ySpare != null && #strings.length(ySpare) > 10}" -->
                            <!--                               class="btn btn-sm btn-primary" -->
                            <!--                               onclick="lookImage(this)">-->
                            <!--                                查看图片</a>-->
                        </div>
                        <table id="bootstrap-table"></table>
                    </div>
                    <!--按钮-->
                    <div class="col-sm-12 entering-bt" style="justify-content: center;">
                        <button type="button" class="btn btn-sm btn-info" onclick="dispatch()">通过并派单
                        </button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <button type="button" class="btn btn-sm btn-warning" onclick="closeItem()">关闭
                        </button>&nbsp;
                    </div>
                </div>

            </div>
            <!--     右       -->
            <div class="col-sm-4 " style="margin: 0;margin-top:5px;padding: 0">
                <div class="col-sm-12 entering-page" style="margin-top: 0">
                    <!--   来信基本信息     -->
                    <div class="col-sm-12 tltieBoder">
                        <div class="blueBorder"></div>
                        <h4 style="margin:0 0 0 10px">来信基本信息</h4>
                    </div>

                    <div class="form-group col-sm-12" style="margin-bottom: 0px">
                        <label class="col-sm-3 control-label entering-pd">工单编号：</label>
                        <div class="col-sm-9">
                            <span class="tworkformprocess-span">[[*{workFormNo}]]</span>
                            <input name="workFormNo" th:field="*{workFormNo}" type="hidden"/>
                        </div>
                    </div>
                    <div class="form-group col-sm-12" style="margin-bottom: 0px">
                        <label class="col-sm-3 control-label entering-pd">工单性质：</label>
                        <div class="col-sm-9">
                            <input name="setProName" th:field="*{setProName}" type="hidden"/>
                            <input name="setProId" id="htbProID" th:field="*{setProId}" type="hidden"/>
                            <span class="tworkformprocess-span">[[*{setProName}]]</span>
                        </div>
                    </div>
                    <!--单选-->
                </div>
                <!--类案推荐-->
                <div class="col-sm-12 entering-page" style="height: 422px;overflow: auto">
                    <div class="col-sm-12 tltieBoder">
                        <div class="blueBorder"></div>
                        <h4 style="margin:0 0 0 10px">类案推荐</h4>
                    </div>
                    <div class="main-content" style="margin: 0;padding: 0">
                        <div class="col-sm-12">
                            <div class="work-order box" style="border-top:0;margin-top: 10px">
                                <div class="content">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </form>
</div>

<script th:src="@{/ajax/libs/layui/laydate.js}"></script>
<th:block th:include="include :: footer"/>
<script th:src="@{/ajax/libs/bootstrap-switch/bootstrap-switch.min.js}"></script>
<script th:src="@{/ajax/libs/jQuery-ui/jquery-ui.js}"></script>
<script th:src="@{/ajax/libs/qxEasyUI/jquery.easyui.min.js}"></script>
<script th:src="@{/js/wsendorder.js}"></script>
<script>
    $('[name="isAutoExtend"]').bootstrapSwitch({
        onText: "是",
        offText: "否",
        onColor: "success",
        offColor: "info",
        size: "mini",
        onSwitchChange: function (event, state) {
            if (state === true) {
                $(this).val(1);
            } else {
                $(this).val(0);
            }
        }
    });
    $('[name="openX"]').bootstrapSwitch({
        onText: "是",
        offText: "否",
        onColor: "success",
        offColor: "info",
        size: "mini",
        onSwitchChange: function (event, state) {
            if (state === true) {
                $(this).val(1);
            } else {
                $(this).val(0);
            }
        }
    });
    $('[name="reportFlag"]').bootstrapSwitch({
        onText: "是",
        offText: "否",
        onColor: "success",
        offColor: "info",
        size: "mini",
        onSwitchChange: function (event, state) {
            if (state === true) {
                $(this).val(1);
            } else {
                $(this).val(0);
            }
        }
    });
    $('[name="fromSex"]').bootstrapSwitch({
        onText: "是",
        offText: "否",
        onColor: "success",
        offColor: "info",
        size: "mini",
        onSwitchChange: function (event, state) {
        }
    });
    $('[name="openFrom"]').bootstrapSwitch({
        onText: "是",
        offText: "否",
        onColor: "success",
        offColor: "info",
        size: "mini",
        onSwitchChange: function (event, state) {
        }
    });

    var prefix = ctx + "system/mTelRcd";
    var send = ctx + "system/sendBack";
    var work = ctx + "system/wsMail";
    var hierarchy = [[${param.hierarchy == null ? 0 :param.hierarchy}]];
    function dispatch() {
        let bootstrapTable = $("#bootstrap-table").bootstrapTable('getData', false);
        if (bootstrapTable.length == 0) {
            $.modal.alertWarning("请选择拟办部门");
            return false;
        }
        if ($.validate.form()) {
            // 记住标签分页列表地址（从哪个列表点进去的）
            var topWindow = $(window.parent.document);
            //刷新市上待派信件工单列表
            if(hierarchy == 1) $('.page-tabs-content',topWindow).find('.active').attr('data-panel','/system/mMailWF/rManage/wfDraftList');
            //刷新区县待派信件工单列表
            else if(hierarchy == 2) $('.page-tabs-content',topWindow).find('.active').attr('data-panel','/system/mMailWF/rManage/wfDraftListWllz');
            var data = $('#form-user-add').serializeArray();
            $.operate.saveTab(work + "/dispatch", data);
        }
    }


    $('#qxCT').combotree({
        url: '/system/common/findContentCate',
        required: false,
        onSelect: function (record) {
            $("#txtDcntAcode").val(record.id);
            $("#txtDCntAName").val(record.text);
        }
    });

    function proposed() {
        let pkId = $('#pkId').val();
        let telId = $('#originFK').val();
        var url = work + "/proposed/" + pkId+"?wfId="+pkId+"&telId="+telId;
        var width = '80%';
        debugger
        // $.modal.open('拟办部门', url, width);
        var layerIdx = parent.layer.getFrameIndex(window.name);
        var iframeName = layerIdx ? 'layui-layer-iframe'+layerIdx : window.name;
        var config = {
            id: 'deptdialog',
            title: '拟办部门',
            width: width,
            url: url,
            callBack: function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler(iframeName);
            }
        };
        $.modal.openOptions(config);
    }

    function refreshTable() {
        $.table.refresh();
    }

    //呈批
    function transfer(){
        if($("#ZJ").text() == '已呈批') return false;
        var fmSpare = $('#fmSpare').val();
        //网络理政件呈批
        if(fmSpare < 50000) {
            var params = {
                flagString: "呈批至" + $("#spareString").val() + "的信箱",
                spareString: $("#spareString").val(),
                ddlTelSort: $("#dfmClaNo option:selected").val(),
                ddlArea: $("#fmAreaNo option:selected").val(),
                txtDcntAcode: $("#txtDcntAcode").val(),
                wfId: $("#pkId").val(),
                pkId: $("#originFK").val(),
            };
            commitAjaxForm(params);
        }
        //后台自建信件呈批
        else if(fmSpare >= 50000) {
            let url = ctx + "system/wsMail/submitForApproval";
            var config = {
                id: 'forApproval',
                title: '请选择呈批信箱',
                width: '50%',
                height: '65%',
                url: url,
                callBack: forApproval
            };
            $.modal.openOptions(config);
        }
    }

    function forApproval(index, layero){
        let rows = layero.find("iframe")[0].contentWindow.getSelections();
        if (rows.length === 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var spareString = rows[0].submit_name + rows[0].name;
        let params = {
            flag: $("#zjflag").val(),
            spareString: spareString,
            flagString: "呈批至" + spareString + "的信箱",
            ddlTelSort: $("#dfmClaNo option:selected").val(),
            ddlArea: $("#fmAreaNo option:selected").val(),
            txtDcntAcode: $("#txtDcntAcode").val(),
            pkId: $("#originFK").val(),
            wfId: $("#pkId").val(),
            mailboxNo: rows[0].submit_id
        };
        commitAjaxForm(params);
        $.modal.close(index);
    }

    function commitAjaxForm(params) {
        $.modal.confirm("是否确定呈批："+params.spareString,function (){
            let url = ctx + "system/wsMail/notReplayForApproval";
            $.ajax({
                url: url,
                type:"post",
                data: params,
                dataType:"json",
                beforeSend: function() {
                    $("#ZJ").prop("disabled", true);
                    beforeSend();
                },
                success:function(result){
                    if(result.msg == "操作成功"){
                        $.modal.msgSuccess('呈批成功！');
                        $("#ZJ").text('已呈批');
                        $("#ZJ").unbind('click');
                    }else {
                        $.modal.msgError(result.msg);
                    }
                },
                complete: function() {
                    $("#ZJ").prop("disabled", false);
                    completeSend();
                }
            });
        });
    }
</script>
</body>
</html>

